//
//  Hear_PhonographController.m
//  Hear
//
//  Created by mac on 2018/4/26.
//  Copyright © 2018年 mac. All rights reserved.
//  留声机

#import "Hear_PhonographController.h"

#import "Hear_PhonographView.h" // 推荐view
#import "Hear_BaseModel.h" // 基础model

#import "Hear_SearchViewController.h" // 搜索
#import "HRSearchToolView.h" // 筛选
#import "Hear_AddNewTopicViewController.h" // 发布话题

#import "Hear_AnswerScrollViewController.h" // 回答列表展示

#import "Hear_AnswerViewController.h" // 回答话题

#import "HRDynamicViewController.h" // 个人主页

#import "HRUMShareTool.h" // 分享

#import "HRFollowDyanmicInfoViewController.h" // 详情

#import "Track.h"
#import "DOUAudioStreamer.h"

@interface Hear_PhonographController () <UIScrollViewDelegate>

/** 推荐按钮 */
@property (nonatomic, strong) UIButton *recommendbtn;
/** 最新按钮 */
@property (nonatomic, strong) UIButton *newestbtn;

/** 推荐底层scrollview */
@property (nonatomic, strong) UIScrollView *rootScroll;

@property (nonatomic, strong) NSMutableDictionary *param;
@property (nonatomic, assign) int page;

/** 推荐数据源 */
@property (nonatomic, strong) NSMutableArray *dataSource;

/** 存储点击状态 */
@property (nonatomic, strong) NSMutableArray *clickType;

/** 最新底层scrollview */
@property (nonatomic, strong) UIScrollView *newestScroll;

@property (nonatomic, strong) NSMutableDictionary *newestparam;
@property (nonatomic, assign) int newestpage;

/** 最新数据源 */
@property (nonatomic, strong) NSMutableArray *newestdata;

/** 存储点击状态 */
@property (nonatomic, strong) NSMutableArray *newestclick;

/** 数据数量 */
@property (nonatomic, assign) NSInteger totalcount;

#pragma mark 播放器
/** 播放器 */
@property (nonatomic, strong) AVPlayer *player;

@property (nonatomic, strong) AVPlayerItem *item;

@property (nonatomic, strong) DOUAudioStreamer *streamer;

/** 播放失败的音频文件 */
@property (nonatomic, copy) NSString *videoStr;

#pragma mark 筛选参数
/** 性别 */
@property (nonatomic, assign) int Sex;

#pragma mark 长按参数模型
/** 长按参数模型 */
@property (nonatomic, strong) Hear_PhonographRecommendModel *model;

/** 不感兴趣书 */
@property (nonatomic, assign) NSInteger uninterestedcount;

/** 举报数 */
@property (nonatomic, assign) NSInteger reportcount;

@property (nonatomic, copy) NSString *change;

/** 当前音频播放时长 */
@property (nonatomic, assign) CGFloat currentplayTime;

/** 记录数组 */
@property (nonatomic, strong) NSMutableArray *recordArr;

@end

@implementation Hear_PhonographController

#pragma mark Set
- (NSMutableDictionary *)param {
    if (!_param) {
        _param = [NSMutableDictionary dictionary];
    }
    return _param;
}

- (NSMutableArray *)dataSource {
    if (!_dataSource) {
        _dataSource = [NSMutableArray array];
    }
    return _dataSource;
}

- (NSMutableArray *)clickType {
    if (!_clickType) {
        _clickType = [NSMutableArray array];
    }
    return _clickType;
}

- (NSMutableDictionary *)newestparam {
    if (!_newestparam) {
        _newestparam = [NSMutableDictionary dictionary];
    }
    return _newestparam;
}

- (NSMutableArray *)newestdata {
    if (!_newestdata) {
        _newestdata = [NSMutableArray array];
    }
    return _newestdata;
}

- (NSMutableArray *)newestclick {
    if (!_newestclick) {
        _newestclick = [NSMutableArray array];
    }
    return _newestclick;
}

- (NSMutableArray *)recordArr {
    if (!_recordArr) {
        _recordArr = [NSMutableArray array];
    }
    return _recordArr;
}

#pragma mark loadview
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.translucent = NO;
    
    [self registerNotification];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.translucent = YES;
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    
    [self hiddenBtn];
    
    if (!self.clickType.count) {
        return;
    } else {
        if (self.recommendbtn.selected) {
            NSInteger index = self.rootScroll.contentOffset.y / self.rootScroll.frame.size.height;
            Hear_PhonographView *view = self.rootScroll.subviews[index];
            if ([self.clickType[index] isEqual:@NO]) {
                [self.clickType replaceObjectAtIndex:index withObject:@YES];
                view.playbtn.hidden = NO;
                [view.playbtn setImage:GetImgWithStr(@"Phonograph_play") forState:UIControlStateNormal];
                [self.player pause];
                [self.streamer pause];
            }
        } else {
            NSInteger index = self.newestScroll.contentOffset.y / self.newestScroll.frame.size.height;
            Hear_PhonographView *view = self.newestScroll.subviews[index];
            if ([self.newestclick[index] isEqual:@NO]) {
                [self.newestclick replaceObjectAtIndex:index withObject:@YES];
                view.playbtn.hidden = NO;
                [view.playbtn setImage:GetImgWithStr(@"Phonograph_play") forState:UIControlStateNormal];
                [self.player pause];
                [self.streamer pause];
            }
        }
    }
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
    
    [[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"cacheTime"];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerItemEnd) name:AVPlayerItemDidPlayToEndTimeNotification object:self.item];
    
    // 默认推荐
    self.recommendbtn.selected = YES;
    [self creatDefaultParam];
    
}

#pragma mark 注册通知
- (void)registerNotification {
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Hear_PhonographlongGesAction:) name:@"Hear_PhonographlongGes" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Hear_PhonographTitleTapAction:) name:@"Hear_PhonographTitleTapAction" object:nil];
    //    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Hear_PhonographShareAction:) name:@"Hear_PhonographShare" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Hear_PhonographAnswerAction:) name:@"Hear_PhonographAnswer" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Hear_PhonographPlayAction:) name:@"Hear_PhonographPlay" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Hear_PhonographRotatingImgAction:) name:@"Hear_PhonographRotatingImg" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Hear_PhonographHeaderTapAction:) name:@"Hear_PhonographHeaderTap" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Hear_PhonographFavoriteAction:) name:@"Hear_PhonographFavorite" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Hear_PhonographCommentAction:) name:@"Hear_PhonographComment" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Hear_PhonographRotatingTapAction:) name:@"Hear_PhonographRotatingTap" object:nil];
}

- (void)networkDidReceiveMessage:(NSNotification *)sender {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [JPUSHService setAlias:USERID completion:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {
            DDLog(@"iResCode==%d iAlias====%@",iResCode,iAlias);
        } seq:0];
    });
}

#pragma mark 主界面
- (void)setupUI {
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkDidReceiveMessage:) name:kJPFNetworkDidLoginNotification object:nil];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    if ([self respondsToSelector:@selector(setAutomaticallyAdjustsScrollViewInsets:)]){
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    
    UIView *titileview = [UIView new];
    titileview.backgroundColor = [UIColor clearColor];
    titileview.size = CGSizeMake(110, 20);
    
    UIButton *recommendbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [recommendbtn setTitle:@"推荐" forState:UIControlStateNormal];
    [recommendbtn setTitleColor:[UIColor colorWithHexString:@"#A0A0A0"] forState:UIControlStateNormal];
    [recommendbtn setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateSelected];
    recommendbtn.titleLabel.font = [UIFont systemFontOfSize:17];
    recommendbtn.frame = CGRectMake(0, 0, 40, 20);
    [recommendbtn addTarget:self action:@selector(recommendbtnAction:) forControlEvents:UIControlEventTouchUpInside];
    self.recommendbtn = recommendbtn;
    [titileview addSubview:recommendbtn];
    
    UIButton *newestbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [newestbtn setTitle:@"最新" forState:UIControlStateNormal];
    [newestbtn setTitleColor:[UIColor colorWithHexString:@"#A0A0A0"] forState:UIControlStateNormal];
    [newestbtn setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateSelected];
    newestbtn.titleLabel.font = [UIFont systemFontOfSize:17];
    [newestbtn addTarget:self action:@selector(newestbtnAction:) forControlEvents:UIControlEventTouchUpInside];
    newestbtn.frame = CGRectMake(70, 0, 40, 20);
    self.newestbtn = newestbtn;
    [titileview addSubview:newestbtn];
    
    self.navigationItem.titleView = titileview;
    
    //    UIView *leftview = [UIView new];
    //    leftview.backgroundColor = [UIColor clearColor];
    //    leftview.size = CGSizeMake(65 * scaleWidth, 20 * scaleHeight);
    //    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftview];;
    
    UIButton *searchbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [searchbtn setBackgroundImage:[UIImage imageNamed:@"搜索"] forState:UIControlStateNormal];
    searchbtn.size = CGSizeMake(19.5, 20);
    [searchbtn addTarget:self action:@selector(searchbtnAction) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:searchbtn];
    //    [leftview addSubview:searchbtn];
    //    [searchbtn mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.leading.centerY.mas_equalTo(leftview);
    //        make.size.mas_equalTo(CGSizeMake(19.5 * scaleWidth, 20 * scaleHeight));
    //    }];
    
    //    UIButton *filterbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    //    [filterbtn setBackgroundImage:[UIImage imageNamed:@"筛选"] forState:UIControlStateNormal];
    //    [filterbtn addTarget:self action:@selector(filterbtnAction) forControlEvents:UIControlEventTouchUpInside];
    //    [leftview addSubview:filterbtn];
    //    [filterbtn mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.trailing.centerY.mas_equalTo(leftview);
    //        make.size.mas_equalTo(CGSizeMake(20 * scaleWidth, 17.5 * scaleHeight));
    //    }];
    
    UIButton *createbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [createbtn addTarget:self action:@selector(createbtnAction) forControlEvents:UIControlEventTouchUpInside];
    [createbtn setBackgroundImage:[UIImage imageNamed:@"创建话题"] forState:0];
    createbtn.size = CGSizeMake(17.5, 17.5);
    UIBarButtonItem *createBtn = [[UIBarButtonItem alloc] initWithCustomView:createbtn];
    [self.navigationItem setRightBarButtonItem:createBtn];
    
    BOOL firstLaunch = [[NSUserDefaults standardUserDefaults] boolForKey:@"isFirstEnter"];
    if (!firstLaunch) {
        UIWindow *window = [UIApplication sharedApplication].keyWindow;
        UIImageView *shadowimg = [[UIImageView alloc] initWithImage:GetImgWithStr(@"留声机—引导")];
        shadowimg.frame = window.bounds;
        shadowimg.userInteractionEnabled = YES;
        [window addSubview:shadowimg];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(firstEnterTap)];
        [shadowimg addGestureRecognizer:tap];
    }
    
}

- (void)firstEnterTap {
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isFirstEnter"];
    
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    id view = [[window subviews] lastObject];
    if([view isKindOfClass:[UIImageView class]]){
        
        UIImageView *bg = (UIImageView *)view;
        [UIView animateWithDuration:0.3f animations:^{
            bg.alpha = 0;
        } completion:^(BOOL finished) {
            [bg removeFromSuperview];
            [self.player play];
        }];
        
    }
}

#pragma mark 推荐
- (void)creatDefaultParam {
    
    NSInteger totalCount = [[NSUserDefaults standardUserDefaults] integerForKey:@"TotalCount"];
    NSInteger page = [[NSUserDefaults standardUserDefaults] integerForKey:@"Currentpage"];
    
    if (totalCount == 0 || totalCount / 10 <= page + 1) {
        self.page = 0;
    } else {
        self.page = page + 1;
    }
    
    [self.param setObject:[NSString stringWithFormat:@"%d", 10] forKey:@"PageSize"];
    [self.param setObject:USERID forKey:@"CurrentUserLocalId"];
    [self.param setObject:[NSString stringWithFormat:@"%d", self.page] forKey:@"PageIndex"];
    [self requestRecommendData];
}

- (void)requestRecommendData {
    
    [MBProgressHUD showHUDAddedTo:WINDOW animated:YES];
    
    YTKApi *api = [YTKApi apiGetWithUrl:@"SoundInfo/Get_GetSoundHot" para:self.param];
    [api getSuccessToken:^() {
        api.foceNoTocken = NO;
        [api setRequestSerializerType:YTKRequestSerializerTypeJSON];
        [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
            
            NSDictionary *dict = request.responseJSONObject;
            
            if ([dict[@"CodeStatus"] integerValue] == 20000) {
                
                NSString *jsonStr = dict[@"BodyContent"];
                
                NSData *jsonData = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
                NSError *err;
                NSDictionary *dic = [NSJSONSerialization
                                     JSONObjectWithData:jsonData
                                     options:NSJSONReadingMutableContainers
                                     error:&err];
                
                if ([dict[@"Message"] isEqualToString:@"暂无数据"]) {
                    
                    
                } else {
                    
                    if(err) {
                        
                    } else {
                        
                        [[NSUserDefaults standardUserDefaults] setInteger:self.page forKey:@"Currentpage"];
                        
                        Hear_BaseModel *baseModel = [Hear_BaseModel modelWithDictionary:dic];
                        
                        [[NSUserDefaults standardUserDefaults] setInteger:baseModel.TotalCount forKey:@"TotalCount"];
                        
                        self.totalcount = baseModel.TotalCount;
                        
                        for (Hear_PhonographRecommendModel *model in baseModel.List) {
                            [self.dataSource addObject:model];
                        }
                        
                        for (int i = 0; i < self.dataSource.count; i++) {
                            [self.clickType addObject:@NO];
                        }
                        
                        dispatch_async(dispatch_get_main_queue(), ^{
                            
                            static dispatch_once_t onceToken;
                            dispatch_once(&onceToken, ^{
                                [MBProgressHUD hideHUDForView:WINDOW animated:YES];
                                
                                [self creatMainView];
                                
                                Hear_PhonographView *currentView = self.rootScroll.subviews[0];
                                
                                currentView.model = self.dataSource[0];
                                
                                [self creatPlayerByModel:self.dataSource[0]];
                                [currentView.rotatingImg resumeRotate];
                                
                                BOOL firstLaunch = [[NSUserDefaults standardUserDefaults] boolForKey:@"isFirstEnter"];
                                if (!firstLaunch) {} else {
                                    [self.player play];
                                }
                            });
                            
                            BOOL isLoad = [[NSUserDefaults standardUserDefaults] boolForKey:@"LoadMainView"];
                            
                            if (isLoad) {
                                [MBProgressHUD hideHUDForView:WINDOW animated:YES];
                                
                                [self creatMainView];
                                
                                Hear_PhonographView *currentView = self.rootScroll.subviews[0];
                                
                                currentView.model = self.dataSource[0];
                                
                                [self creatPlayerByModel:self.dataSource[0]];
                                [currentView.rotatingImg resumeRotate];
                                
                                BOOL firstLaunch = [[NSUserDefaults standardUserDefaults] boolForKey:@"isFirstEnter"];
                                if (!firstLaunch) {} else {
                                    [self.player play];
                                }
                            }
                            
                            NSInteger page = [[NSUserDefaults standardUserDefaults] integerForKey:@"Currentpage"];
                            
                            if ([self.change isEqualToString:@"1"] && page == self.page) {
                                [MBProgressHUD hideHUDForView:WINDOW animated:YES];

                                [self creatMainView];

                                Hear_PhonographView *currentView = self.rootScroll.subviews[0];

                                currentView.model = self.dataSource[0];

                                [self creatPlayerByModel:self.dataSource[0]];
                                [currentView.rotatingImg resumeRotate];
                                [self.player play];
                            }
                            
                            [MBProgressHUD hideHUDForView:WINDOW animated:YES];
                            
                            [self addScrollviewSize];
                            
                        });
                    }
                }
            }
            
        } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
            
        }];
    }];
}

#pragma mark 推荐界面
- (void)creatMainView {
    [self.view removeAllSubviews];
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    CGFloat height = ScreenHeight - kTabBarHeight- kTopHeight;
    
    UIScrollView *rootScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, height)];
    rootScroll.showsVerticalScrollIndicator = false;
    rootScroll.showsHorizontalScrollIndicator = false;
    rootScroll.pagingEnabled = YES;
    rootScroll.delegate = self;
    
    self.rootScroll = rootScroll;
    
    self.rootScroll.contentSize = CGSizeMake(ScreenWidth, height * self.dataSource.count);
    
    [self.view addSubview:rootScroll];
    
    for (int i = 0; i < self.dataSource.count; i++) {
        Hear_PhonographView *view = [[Hear_PhonographView alloc] initWithFrame:CGRectMake(0, height * i, ScreenWidth, height)];
        
        [self.rootScroll addSubview:view];
    }
}

- (void)addScrollviewSize {
    
    CGFloat height = ScreenHeight - kTabBarHeight- kTopHeight;
    
    NSInteger datacount = self.dataSource.count;
    NSInteger viewcount = self.rootScroll.subviews.count;
    
    Hear_PhonographView *lastview = (Hear_PhonographView *)self.rootScroll.subviews.lastObject;
    
    self.rootScroll.contentSize = CGSizeMake(ScreenWidth, self.dataSource.count * height);
    
    NSInteger count;
    if (datacount - viewcount > 0) {
        count = datacount - viewcount;
    } else {
        count = viewcount - datacount;
    }
    
    for (int i = 0; i < count; i++) {
        Hear_PhonographView *view = [[Hear_PhonographView alloc] initWithFrame:CGRectMake(0, lastview.bottom + height * i, ScreenWidth, height)];
        [self.rootScroll addSubview:view];
    }
    
}

#pragma mark 最新
- (void)creatNewestDefaultParam {
    self.newestpage = 0;
    [self.newestparam setObject:[NSString stringWithFormat:@"%d", 10] forKey:@"PageSize"];
    [self.newestparam setObject:USERID forKey:@"CurrentUserLocalId"];
    [self.newestparam setObject:[NSString stringWithFormat:@"%d", self.newestpage] forKey:@"PageIndex"];
    [self requestNewestData];
}

- (void)requestNewestData {
    
    [MBProgressHUD showHUDAddedTo:WINDOW animated:YES];
    
    YTKApi *api = [YTKApi apiGetWithUrl:@"SoundInfo/Get_GetSoundLatest" para:self.newestparam];
    [api getSuccessToken:^() {
        api.foceNoTocken = NO;
        [api setRequestSerializerType:YTKRequestSerializerTypeJSON];
        [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
            
            NSDictionary *dict = request.responseJSONObject;
            
            if ([dict[@"CodeStatus"] integerValue] == 20000) {
                
                NSString *jsonStr = dict[@"BodyContent"];
                
                NSData *jsonData = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
                NSError *err;
                NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                                    options:NSJSONReadingMutableContainers
                                                                      error:&err];
                if(err) {
                    
                } else {
                    Hear_BaseModel *baseModel = [Hear_BaseModel modelWithDictionary:dic];
                    self.totalcount = baseModel.TotalCount;
                    
                    for (Hear_PhonographRecommendModel *model in baseModel.List) {
                        [self.newestdata addObject:model];
                    }
                    
                    for (int i = 0; i < self.newestdata.count; i++) {
                        [self.newestclick addObject:@NO];
                    }
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        
                        if (self.newestpage == 0) {
                            [MBProgressHUD hideHUDForView:WINDOW animated:YES];
                            
                            [self creatNewestView];
                            
                            // 给第一个界面赋值
                            Hear_PhonographView *currentView = self.newestScroll.subviews[0];
                            
                            currentView.model = self.newestdata[0];
                            
                            [self creatPlayerByModel:self.newestdata[0]];
                            [currentView.rotatingImg startRotating];
                            [self.player play];
                            
                        } else {
                            
                            [MBProgressHUD hideHUDForView:WINDOW animated:YES];
                            
                            [self addNewestScrollviewSize];
                        }
                        
                    });
                }
            }
            
        } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
            
        }];
    }];
}

#pragma mark 最新界面
- (void)creatNewestView {
    [self.view removeAllSubviews];
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    CGFloat height = ScreenHeight - kTabBarHeight- kTopHeight;
    
    UIScrollView *rootScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, height)];
    rootScroll.showsVerticalScrollIndicator = false;
    rootScroll.showsHorizontalScrollIndicator = false;
    rootScroll.pagingEnabled = YES;
    rootScroll.delegate = self;
    
    self.newestScroll = rootScroll;
    
    self.newestScroll.contentSize = CGSizeMake(ScreenWidth, height * self.newestdata.count);
    
    [self.view addSubview:rootScroll];
    
    for (int i = 0; i < self.newestdata.count; i++) {
        Hear_PhonographView *view = [[Hear_PhonographView alloc] initWithFrame:CGRectMake(0, height * i, ScreenWidth, height)];
        
        [self.newestScroll addSubview:view];
    }
}

- (void)addNewestScrollviewSize {
    
    CGFloat height = ScreenHeight - kTabBarHeight- kTopHeight;
    
    NSInteger datacount = self.newestdata.count;
    NSInteger viewcount = self.newestScroll.subviews.count;
    
    Hear_PhonographView *lastview = (Hear_PhonographView *)self.newestScroll.subviews.lastObject;
    
    self.newestScroll.contentSize = CGSizeMake(ScreenWidth, self.newestdata.count * height);
    
    NSInteger count;
    if (datacount - viewcount > 0) {
        count = datacount - viewcount;
    } else {
        count = viewcount - datacount;
    }
    
    for (int i = 0; i < count; i++) {
        Hear_PhonographView *view = [[Hear_PhonographView alloc] initWithFrame:CGRectMake(0, lastview.bottom + height * i, ScreenWidth, height)];
        [self.newestScroll addSubview:view];
    }
}

#pragma mark 数据展示
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    [self hiddenBtn];
    
    [self writeListen];
    
    if (scrollView == self.rootScroll) {
        
        NSInteger index = scrollView.contentOffset.y / self.rootScroll.frame.size.height;
        
        if (index == 1) {
            [self addTopicGuide];
        }
        
        [[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithFormat:@"%ld", index] forKey:@"Hear_Index"];
        
        Hear_PhonographView *currentView = scrollView.subviews[index];
        
        currentView.model = self.dataSource[index];
        
        [self creatPlayerByModel:currentView.model];
        
        if ([self.clickType[index] isEqual:@NO]) {
            [self.player play];
            [self.streamer play];
            [currentView.rotatingImg resumeRotate];
        } else {
            [self.player pause];
            [self.streamer pause];
            [currentView.rotatingImg stopRotating];
        }
        
        if (self.totalcount <= 10 && index == self.totalcount - 1) {
            [self showMessage:@"已经到底了!" atPosition:ShowPosition_Bottom];
        } else {
            
            NSInteger count;
            if (_uninterestedcount != 0) {
                count = _uninterestedcount + 1;
            } else {
                count = 1;
            }
            
            if (index != 0 && (index + count) % 10 == 0) {
                // 对10取余,为0时则进行数据请求
                self.page += 1;
                [self.param setObject:[NSString stringWithFormat:@"%d", 10] forKey:@"PageSize"];
                [self.param setObject:USERID forKey:@"CurrentUserLocalId"];
                [self.param setObject:[NSString stringWithFormat:@"%d", self.page] forKey:@"PageIndex"];
                [self requestRecommendData];
                
            } else if (self.rootScroll.subviews.count % 10 && self.page != 0) {
                [self creatDefaultParam];
            }
            
        }
        
    }
    
    if (scrollView == self.newestScroll) {
        
        NSInteger index = scrollView.contentOffset.y / self.newestScroll.frame.size.height;
        
        Hear_PhonographView *currentView = scrollView.subviews[index];
        
        currentView.model = self.newestdata[index];
        
        [self creatPlayerByModel:currentView.model];
        
        if ([self.newestclick[index] isEqual:@NO]) {
            [self.player play];
            [self.streamer play];
            [currentView.rotatingImg resumeRotate];
        } else {
            [self.player pause];
            [self.streamer pause];
            [currentView.rotatingImg stopRotating];
        }
        
        if (self.totalcount <= 10 && index == self.totalcount - 1) {
            [self showMessage:@"已经到底了!" atPosition:ShowPosition_Bottom];
        } else {
            
            NSInteger count;
            if (_reportcount != 0) {
                count = _reportcount + 1;
            } else {
                count = 1;
            }
            
            if (index != 0 && (index + count) % 10 == 0) {
                // 对10取余,为0时则进行数据请求
                self.newestpage += 1;
                [self.newestparam setObject:[NSString stringWithFormat:@"%d", 10] forKey:@"PageSize"];
                [self.newestparam setObject:USERID forKey:@"CurrentUserLocalId"];
                [self.newestparam setObject:[NSString stringWithFormat:@"%d", self.newestpage] forKey:@"PageIndex"];
                [self requestNewestData];
            }
        }
    }
    
}

#pragma mark 收听记录
- (void)writeListen {
    if (self.recommendbtn.selected) {
        
        NSInteger index = self.rootScroll.contentOffset.y / self.rootScroll.frame.size.height;
        
        NSInteger dataindex;
        if (index == 0) {
            dataindex = 0;
        } else {
            dataindex = index - 1;
        }
        
        Hear_PhonographRecommendModel *model = self.dataSource[dataindex];
        
        NSMutableDictionary *tempdic = [NSMutableDictionary dictionary];
        
        tempdic[@"UserLocalId"] = USERID;
        tempdic[@"SoundLocalId"] = model.LocalId;
        tempdic[@"Index"] = 0;
        tempdic[@"ListenStartTime"] = [self getCurrentTime];
        tempdic[@"ListenDuration"] = [NSString stringWithFormat:@"%f", self.currentplayTime];
        
        [self.recordArr addObject:tempdic];
        NSError *error = nil;
        
        NSString *recordJson = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:self.recordArr options:NSJSONWritingPrettyPrinted error:&error] encoding:NSUTF8StringEncoding];
        
        [[NSUserDefaults standardUserDefaults] setObject:recordJson forKey:@"RecordVideo"];
        
        for (int i = 0; i < self.recordArr.count; i++) {
//            if (self.dataSource.count >= index) {
                Hear_PhonographRecommendModel *model = self.dataSource[index];
                
                NSDictionary *record = self.recordArr[i];
                
                if ([model.LocalId isEqualToString:record[@"SoundLocalId"]]) {
                    if (self.recordArr.count == 1) {
                        
                    } else {
                        [self.recordArr removeObject:record];
                        
                        NSString *recordJson = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:self.recordArr options:NSJSONWritingPrettyPrinted error:&error] encoding:NSUTF8StringEncoding];
                        
                        [[NSUserDefaults standardUserDefaults] setObject:recordJson forKey:@"RecordVideo"];
                    }
                }
//            }
        }
        
    } else {
        
        NSInteger index = self.newestScroll.contentOffset.y / self.newestScroll.frame.size.height;
        
        NSInteger dataindex;
        if (index == 0) {
            dataindex = 0;
        } else {
            dataindex = index - 1;
        }
        
        Hear_PhonographRecommendModel *model = self.newestdata[dataindex];
        
        NSMutableDictionary *tempdic = [NSMutableDictionary dictionary];
        
        tempdic[@"UserLocalId"] = USERID;
        tempdic[@"SoundLocalId"] = model.LocalId;
        tempdic[@"Index"] = 0;
        tempdic[@"ListenStartTime"] = [self getCurrentTime];
        tempdic[@"ListenDuration"] = [NSString stringWithFormat:@"%f", self.currentplayTime];
        
        [self.recordArr addObject:tempdic];
        
        NSError *error = nil;
        NSString *recordJson = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:self.recordArr options:NSJSONWritingPrettyPrinted error:&error] encoding:NSUTF8StringEncoding];
        
        [[NSUserDefaults standardUserDefaults] setObject:recordJson forKey:@"RecordVideo"];
        
        for (int i = 0; i < self.recordArr.count; i++) {
            
            Hear_PhonographRecommendModel *model = self.newestdata[index];
            
            NSDictionary *record = self.recordArr[i];
            
            if ([model.LocalId isEqualToString:record[@"SoundLocalId"]]) {
                if (self.recordArr.count == 1) {
                    
                } else {
                    [self.recordArr removeObject:record];
                    
                    NSString *recordJson = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:self.recordArr options:NSJSONWritingPrettyPrinted error:&error] encoding:NSUTF8StringEncoding];
                    
                    [[NSUserDefaults standardUserDefaults] setObject:recordJson forKey:@"RecordVideo"];
                }
            }
        }
        
    }
}

#pragma mark 创建提示
- (void)addTopicGuide {
    
    BOOL firstLaunch = [[NSUserDefaults standardUserDefaults] boolForKey:@"isFirstAddTopic"];
    if (!firstLaunch) {
        UIWindow *window = [UIApplication sharedApplication].keyWindow;
        UIImageView *shadowimg = [[UIImageView alloc] initWithImage:GetImgWithStr(@"留声机—创建话题")];
        shadowimg.frame = CGRectMake(kFullWidth - 100 - 13, kTopHeight, 100, 30);
        shadowimg.userInteractionEnabled = YES;
        [window addSubview:shadowimg];
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isFirstAddTopic"];
            
            [UIView animateWithDuration:0.3f animations:^{
                shadowimg.alpha = 0;
            } completion:^(BOOL finished) {
                [shadowimg removeFromSuperview];
            }];
        });
    }
}

#pragma mark >>>>>>>>>>>>>>播放器<<<<<<<<<<<<<<
- (void)creatPlayerByModel:(Hear_PhonographRecommendModel *)model {
    
    [self.streamer pause];
    self.streamer = nil;
    
    [self.item removeObserver:self forKeyPath:@"status"];
    
    self.videoStr = model.SoundUrl;
    
    self.item = [[AVPlayerItem alloc] initWithURL:GetUrlWithStr(model.SoundUrl)];
    
    self.player = [[AVPlayer alloc] initWithPlayerItem:self.item];
    
    [self.item addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil];
    
    [self.player addPeriodicTimeObserverForInterval:CMTimeMake(1, 1) queue:NULL usingBlock:^(CMTime time) {
        //获取当前时间
        CMTime currentTime = self.player.currentItem.currentTime;
        
        //转成秒数
        double currentPlayTime = currentTime.value / currentTime.timescale;
        
        self.currentplayTime = currentPlayTime;
        
    }];
    
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context {
    if (object == self.player.currentItem) {
        if ([keyPath isEqualToString:@"status"]) {
            
            if (self.player.currentItem.status == AVPlayerItemStatusReadyToPlay){
                
                [_streamer pause];
                
            } else if (self.player.currentItem.status == AVPlayerItemStatusFailed) {
                
                Track *track = [[Track alloc] init];
                track.audioFileURL = [NSURL URLWithString:self.videoStr];
                
                _streamer = nil;
                _streamer = [DOUAudioStreamer streamerWithAudioFile:track];
                
                [_streamer play];
                
            }
            
        }
    }
}

- (void)playerItemEnd {
    
    if (self.recommendbtn.selected) {
        NSInteger index = self.rootScroll.contentOffset.y / self.rootScroll.frame.size.height;
        Hear_PhonographView *view = self.rootScroll.subviews[index];
        view.playbtn.hidden = NO;
        [view.playbtn setImage:GetImgWithStr(@"Phonograph_play") forState:UIControlStateNormal];
        [view.rotatingImg stopRotating];
        [self.clickType replaceObjectAtIndex:index withObject:@YES];
        [self creatPlayerByModel:view.model];
        [self.player pause];
        [self.streamer pause];
    } else {
        NSInteger index = self.newestScroll.contentOffset.y / self.newestScroll.frame.size.height;
        Hear_PhonographView *view = self.newestScroll.subviews[index];
        view.playbtn.hidden = NO;
        [view.playbtn setImage:GetImgWithStr(@"Phonograph_play") forState:UIControlStateNormal];
        [view.rotatingImg stopRotating];
        [self.newestclick replaceObjectAtIndex:index withObject:@YES];
        [self creatPlayerByModel:view.model];
        [self.player pause];
        [self.streamer pause];
    }
    
}

#pragma mark >>>>>>>>>>>>>>界面事件<<<<<<<<<<<<<<
#pragma mark 搜索按钮
- (void)searchbtnAction {
    [self.player pause];
    [self.streamer pause];
    Hear_SearchViewController *vc = [Hear_SearchViewController new];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark 筛选按钮
//- (void)filterbtnAction {
//    [HRSearchToolView showSearchToolView:^(NSDictionary *contentDict) {
//        self.Sex = [contentDict[@"Sex"] intValue];
//        [MobClick event:@"Hearer1"];
//
//        if (self.recommendbtn.selected) {
//            [self creatDefaultParam];
//        } else {
//            [self creatNewestDefaultParam];
//        }
//
//    }];
//}

#pragma mark 创建话题
- (void)createbtnAction {
    [self.player pause];
    [self.streamer pause];
    
    Hear_AddNewTopicViewController *vc = [Hear_AddNewTopicViewController new];
    vc.placeholder = @"请输入你要创建的留声机内容/话题，30-60字为佳";
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark 推荐按钮
- (void)recommendbtnAction:(UIButton *)sender {
    sender.selected = YES;
    self.newestbtn.selected = !sender.selected;
    [self.player pause];
    [self.streamer pause];
    
    [self hiddenBtn];
    
    self.change = @"1";
    
    [self creatDefaultParam];
}

#pragma mark 最新按钮
- (void)newestbtnAction:(UIButton *)sender {
    sender.selected = YES;
    self.recommendbtn.selected = !sender.selected;
    [self.player pause];
    [self.streamer pause];
    [self hiddenBtn];
    
    self.change = @"2";
    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"LoadMainView"];
    
    [self creatNewestDefaultParam];
}

#pragma mark 界面长按事件
- (void)Hear_PhonographlongGesAction:(NSNotification *)sender {
    Hear_PhonographRecommendModel *model = sender.object;
    
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    
    if (self.recommendbtn.selected) {
        self.model = model;
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setImage:GetImgWithStr(@"不感兴趣") forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(uninterestedBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [window addSubview:btn];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.mas_equalTo(window);
            make.size.mas_equalTo(CGSizeMake(75 * scaleWidth, 102.5 * scaleHeight));
        }];
    } else {
        self.model = model;
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setImage:GetImgWithStr(@"举报") forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(reportBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [window addSubview:btn];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.mas_equalTo(window);
            make.size.mas_equalTo(CGSizeMake(75 * scaleWidth, 102 * scaleHeight));
        }];
    }
    
}

#pragma mark 不感兴趣
- (void)uninterestedBtnAction:(UIButton *)sender {
    [self hiddenBtn];
    
    _uninterestedcount += 1;
    
    NSInteger index = self.rootScroll.contentOffset.y / self.rootScroll.frame.size.height;
    
    CGFloat height = ScreenHeight - kTabBarHeight- kTopHeight;
    
    Hear_PhonographRecommendModel *model = self.dataSource[index];
    
    NSDictionary *param = @{
                            @"SoundLocalId":model.LocalId,
                            @"UserLocalId":USERID,
                            @"CreateTime":[self getCurrentTime]
                            };
    
    YTKApi *api = [YTKApi apiPostWithUrl:@"SoundInfo/Post_SaveSoundDislike" para:param];
    
    [api getSuccessToken:^() {
        api.foceNoTocken = NO;
        [api setRequestSerializerType:YTKRequestSerializerTypeJSON];
        
        [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
            
            NSDictionary *dict = request.responseJSONObject;
            
            if ([dict[@"CodeStatus"] integerValue] == 20000) {
                
                [self showMessage:@"收到,我们将减少相关内容的推送" atPosition:ShowPosition_Center];
                
                [self.dataSource removeObjectAtIndex:index];
                [self.clickType removeObjectAtIndex:index];
                
                self.rootScroll.contentSize = CGSizeMake(ScreenWidth, self.dataSource.count * height);
                
                [self.rootScroll setContentOffset:CGPointMake(0, height * (index + 1)) animated:YES];
                
                Hear_PhonographView *currentView = self.rootScroll.subviews[index + 1];
                currentView.model = self.dataSource[index];
                [self creatPlayerByModel:currentView.model];
                
                if ([self.clickType[index] isEqual:@NO]) {
                    [self.player play];
                    [self.streamer play];
                    [currentView.rotatingImg resumeRotate];
                } else {
                    [self.player pause];
                    [self.streamer pause];
                    [currentView.rotatingImg stopRotating];
                }
                
            }
            
        } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
            
        }];
    }];
    
}

#pragma mark 举报
- (void)reportBtnAction:(UIButton *)sender {
    [self hiddenBtn];
    
    _reportcount += 1;
    
    NSInteger index = self.newestScroll.contentOffset.y / self.newestScroll.frame.size.height;
    
    CGFloat height = ScreenHeight - kTabBarHeight- kTopHeight;
    
    Hear_PhonographRecommendModel *model = self.newestdata[index];
    
    NSDictionary *param = @{
                            @"SoundLocalId":model.LocalId,
                            @"UserLocalId":USERID,
                            @"Status":@"0",
                            @"CreateTime":[self getCurrentTime]
                            };
    
    YTKApi *api = [YTKApi apiPostWithUrl:@"SoundInfo/Post_SaveSoundDislike" para:param];
    [api getSuccessToken:^() {
        api.foceNoTocken = NO;
        [api setRequestSerializerType:YTKRequestSerializerTypeJSON];
        [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
            NSDictionary *dict = request.responseJSONObject;
            
            if ([dict[@"CodeStatus"] integerValue] == 20000) {
                
                [self showMessage:@"感谢您的举报,我们将做相关处理" atPosition:ShowPosition_Center];
                
                [self.newestdata removeObjectAtIndex:index];
                [self.newestclick removeObjectAtIndex:index];
                
                self.newestScroll.contentSize = CGSizeMake(ScreenWidth, self.newestdata.count * height);
                
                [self.newestScroll setContentOffset:CGPointMake(0, height * (index + 1)) animated:YES];
                
                Hear_PhonographView *currentView = self.newestScroll.subviews[index + 1];
                currentView.model = self.newestdata[index];
                [self creatPlayerByModel:currentView.model];
                
                if ([self.newestclick[index] isEqual:@NO]) {
                    [self.player play];
                    [self.streamer play];
                    [currentView.rotatingImg resumeRotate];
                } else {
                    [self.player pause];
                    [self.streamer pause];
                    [currentView.rotatingImg stopRotating];
                }
            }
            
        } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
            
        }];
    }];
}

#pragma mark 隐藏按钮
- (void)hiddenBtn {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    id view = [[window subviews] lastObject];
    if([view isKindOfClass:[UIButton class]]){
        
        UIButton *btn = (UIButton *)view;
        [UIView animateWithDuration:0.3f animations:^{
            btn.alpha = 0;
        } completion:^(BOOL finished) {
            [btn removeFromSuperview];
        }];
        
    }
}

#pragma mark 标题点击事件
- (void)Hear_PhonographTitleTapAction:(NSNotification *)sender {
    Hear_PhonographRecommendModel *model = sender.object;
    
    Hear_AnswerScrollViewController *vc = [Hear_AnswerScrollViewController new];
    vc.QuestionID = model.QuestionID;
    [self.navigationController pushViewController:vc animated:YES];
}

//#pragma mark 分享话题
//- (void)Hear_PhonographShareAction:(NSNotification *)sender {
//    Hear_PhonographRecommendModel *model = sender.object;
//    
//    NSString *title = @"";
//    if (model.QuestionText.length){
//        title = model.QuestionText;
//    } else {
//        title = @"我在Hear留下的瞬间";
//    }
//    
//    int value = (arc4random() % 5) + 1;
//    
//    [HRUMShareTool uMShareToolTitle:title andContentStr:[NSString stringWithFormat:@"你有%d个好友回答了这个问题，快来参加吧~", value] andImage:[UIImage imageNamed:@"hearicon"] andShareUrl:[NSString stringWithFormat:@"http://www.dolphinvoice.com/M/VoiceShare/%@", model.LocalId] isSeccess:^(BOOL isSeccess) {
//        
//    }];
//}

#pragma mark 点赞话题
- (void)Hear_PhonographFavoriteAction:(NSNotification *)sender {
    Hear_PhonographRecommendModel *model = sender.object;
    
    if (self.recommendbtn.selected) {
        NSInteger index = self.rootScroll.contentOffset.y / self.rootScroll.frame.size.height;
        [self.dataSource replaceObjectAtIndex:index withObject:model];
        
    } else {
        NSInteger index = self.newestScroll.contentOffset.y / self.newestScroll.frame.size.height;
        [self.newestdata replaceObjectAtIndex:index withObject:model];
    }
}

#pragma mark 回答话题
- (void)Hear_PhonographAnswerAction:(NSNotification *)sender {
    Hear_PhonographRecommendModel *model = sender.object;
    
    Hear_AnswerViewController *vc = [Hear_AnswerViewController new];
    
    vc.model = model;
    
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark 播放话题
- (void)Hear_PhonographPlayAction:(NSNotification *)sender {
    UIButton *playbtn = sender.object;
    
    if (self.recommendbtn.selected) {
        NSInteger index = self.rootScroll.contentOffset.y / self.rootScroll.frame.size.height;
        
        if ([self.clickType[index] isEqual:@NO]) {
            [self.clickType replaceObjectAtIndex:index withObject:@YES];
            playbtn.hidden = NO;
            [playbtn setImage:GetImgWithStr(@"Phonograph_play") forState:UIControlStateNormal];
            [self.player pause];
            [self.streamer pause];
        } else {
            [self.clickType replaceObjectAtIndex:index withObject:@NO];
            playbtn.hidden = YES;
            [self.player play];
            [self.streamer play];
        }
        
    } else {
        NSInteger index = self.newestScroll.contentOffset.y / self.newestScroll.frame.size.height;
        
        if ([self.newestclick[index] isEqual:@NO]) {
            [self.newestclick replaceObjectAtIndex:index withObject:@YES];
            [playbtn setImage:GetImgWithStr(@"Phonograph_play") forState:UIControlStateNormal];
            playbtn.hidden = NO;
            [self.player pause];
            [self.streamer pause];
        } else {
            [self.newestclick replaceObjectAtIndex:index withObject:@NO];
            playbtn.hidden = YES;
            [self.player play];
            [self.streamer play];
        }
        
    }
    
}

- (void)Hear_PhonographRotatingImgAction:(NSNotification *)sender {
    UIImageView *img = sender.object;
    
    if (self.recommendbtn.selected) {
        NSInteger index = self.rootScroll.contentOffset.y / self.rootScroll.frame.size.height;
        if ([self.clickType[index] isEqual:@NO]) {
            [img resumeRotate];
        } else {
            [img stopRotating];
        }
    } else {
        NSInteger index = self.newestScroll.contentOffset.y / self.newestScroll.frame.size.height;
        if ([self.newestclick[index] isEqual:@NO]) {
            [img resumeRotate];
        } else {
            [img stopRotating];
        }
    }
}

#pragma mark 题主头像点击
- (void)Hear_PhonographHeaderTapAction:(NSNotification *)sender {
    
    [self.player pause];
    [self.streamer pause];
    
    Hear_PhonographRecommendModel *model = sender.object;
    
    [MobClick event:@"Hearer8"];
    HRDynamicViewController *dynamicVC = [HRDynamicViewController new];
    
    dynamicVC.currentUserID = model.MasterUserLocalId;
    [self.navigationController pushViewController:dynamicVC animated:YES];
}

#pragma mark 评论事件
- (void)Hear_PhonographCommentAction:(NSNotification *)sender {
    Hear_PhonographRecommendModel *model = sender.object;
    
    if (self.recommendbtn.selected) {
        NSInteger index = self.rootScroll.contentOffset.y / self.rootScroll.frame.size.height;
        [self.dataSource replaceObjectAtIndex:index withObject:model];
        
    } else {
        NSInteger index = self.newestScroll.contentOffset.y / self.newestScroll.frame.size.height;
        [self.newestdata replaceObjectAtIndex:index withObject:model];
    }
    
    HRFollowDyanmicInfoViewController *infoVC = [HRFollowDyanmicInfoViewController new];
    infoVC.dynamicID = model.LocalId;
    [self.navigationController pushViewController:infoVC animated:YES];
}

#pragma mark 转动头像点击
- (void)Hear_PhonographRotatingTapAction:(NSNotification *)sender {
    
    [self.player pause];
    [self.streamer pause];
    
    Hear_PhonographRecommendModel *model = sender.object;
    
    [MobClick event:@"Hearer8"];
    HRDynamicViewController *dynamicVC = [HRDynamicViewController new];
    
    dynamicVC.currentUserID = model.UserLocalId;
    [self.navigationController pushViewController:dynamicVC animated:YES];
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (NSString *)getCurrentTime {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"];
    return [formatter stringFromDate:[NSDate date]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
